var _page = $('.page')
// 加载最新单身列表
var thisload1 = bottlecms.load({
    elem: $('.infinite-gift1'),
    scroll: $('.infinite-scroll1'),
    done: function(page, next) {
        var src = this.elem.attr("pages-src");
        bottlecms.get(src, {
            page: page
        }, function(data) {
            var lis = [];
            for (var o in data.list) {
                lis.push(gift_list_template(data.list[o]))
            }
            next(lis.join(''), lis.length);
        })
    }
})
var thisload2 = bottlecms.load({
    elem: $('.infinite-gift2'),
    scroll: $('.infinite-scroll2'),
    done: function(page, next) {
        var src = this.elem.attr("pages-src");
        bottlecms.get(src, {
            page: page
        }, function(data) {
            var lis = [];
            for (var o in data.list) {
                lis.push(gift_list_template(data.list[o]))
            }
            next(lis.join(''), lis.length);
        })
    }
})



var tabload = function(){
    setTimeout(function() {
        if($('.bcui-tab .bcui-tab-content .item.active .infinite-gift1').length>0){
            thisload1.load();
        }
        else if($('.bcui-tab .bcui-tab-content .item.active .infinite-gift2').length>0){
            thisload2.load();
        }
    }, 100)
}

$(_page).on('click', '.bcui-tab .bcui-tab-title .item', function(event) {
    tabload();
});
tabload();


/*======================================
                模版
=====================================*/
function gift_list_template(v) {
    var html = '<div class="item ub">';
    html+= '<div class="ub-f1 left">';
    if(v){
        html+= '<div class="gift"><img src="' + v.cover + '" /><span>'+v.title+'</span></div>';
    }else{
        html+= '<div class="gift">礼物不存在或已删除</div>';
    }
    if(v){
        html+= '<div class="single">赠送人：<a  href="/m/single/info/' + v.giveId +'"><span class="nickname">'+v.nickname+'</span></a></div>';
    }else{
        html+= '<div class="single">用户不存或已删除</div>';
    }
    html+= '</div>';
    html+= '<div class="info">';

    html+= '<div class="time">'+v.createTime+'</div>';
    html+= '</div>';
    html+= '</div>';

    return html;
}
/*======================================
                页面
=====================================*/